package com.baomidou.springboot.controller.user;

import com.baomidou.mybatisplus.plugins.Page;
import com.baomidou.springboot.common.SortEnum;
import com.baomidou.springboot.entity.File;
import com.baomidou.springboot.service.AboutService;
import com.baomidou.springboot.service.FileService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestMethod;

import javax.servlet.http.HttpServletRequest;

@Controller("userFileController")
@RequestMapping("/userFile")
public class FileController {

    @Autowired
    private AboutService aboutService;
    @Autowired
    private FileService fileService;

    @RequestMapping(value = "/list", method = RequestMethod.GET)
    public String list(HttpServletRequest request, Page<File> page, String id) {
        // 关于我们子菜单
        request.setAttribute("aboutMenuList", aboutService.findBySort(SortEnum.ASC));
        File file = fileService.findById(id);
        request.setAttribute("file", file);
        // 列表
        page.setSize(20);
        request.setAttribute("page", fileService.findPage(page, null == file ? null : file.getMenu()));
        return "user/file/list";
    }

    @RequestMapping(value = "/detail", method = RequestMethod.GET)
    public String detail(HttpServletRequest request, String id) {
        // 关于我们子菜单
        request.setAttribute("aboutMenuList", aboutService.findBySort(SortEnum.ASC));
        // 新闻的动态子菜单
        request.setAttribute("fileMenuList", fileService.findBySort(SortEnum.ASC));
        // 新闻详情
        request.setAttribute("file", fileService.findById(id));
        return "user/file/detail";
    }
}
